﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;
using Microsoft.Office.Tools;

namespace Mars2013plugin
{
    public class InspectorWrapper
    {
        private Outlook.Inspector inspector;
        private CustomTaskPane marsTaskPane;

        public InspectorWrapper(Outlook.Inspector Inspector)
        {
            inspector = Inspector;
            marsTaskPane = Globals.ThisAddIn.CustomTaskPanes.Add(new MarsTaskPaneControl(), "Mars Analytics Pane");

            ((Outlook.InspectorEvents_Event)inspector).Close += new Outlook.InspectorEvents_CloseEventHandler(InspectorWrapper_Close);
            marsTaskPane.VisibleChanged += new EventHandler(marsTaskPane_VisibleChanged);
        }

        void marsTaskPane_VisibleChanged(object sender, EventArgs e)
        {
            Globals.Ribbons[inspector].MarsTaskPaneRibbon.toggleButton1.Checked = marsTaskPane.Visible;

        }

        private void InspectorWrapper_Close()
        {
            if (marsTaskPane != null)
            {
                Globals.ThisAddIn.CustomTaskPanes.Remove(marsTaskPane);
            }
            marsTaskPane = null;

            ((Outlook.InspectorEvents_Event)inspector).Close -= new Outlook.InspectorEvents_CloseEventHandler(InspectorWrapper_Close);
            inspector = null;
        }

        public CustomTaskPane CustomTaskPane
        {
            get
            {
                return marsTaskPane;
            }
        }

    }
}
